<?php
	function getShopperAddress()
	{
		$tables = array();
		$tables[0] = 'ex_shoppers';
		
		$fields = array();
		$fields[0] = 'address';
		
		$whereClause = 'memberID="'.$_SESSION['shopper'].'"';
		
		$data = SQLRecover($tables, $fields, $whereClause);
		return $data['address'][0];
		
	}
	function getShopperLocation()
	{
		$tables = array();
		$tables[0] = 'ex_shoppers';
		
		$fields = array();
		$fields[0] = 'location';
		
		$whereClause = 'memberID="'.$_SESSION['shopper'].'"';
		
		$data = SQLRecover($tables, $fields, $whereClause);
		
		return $data['location'][0];
	}
	function decipherShipping($name)
	{
		if($name == 'Metro Manila')
		{
			$shID = '1';
		}
		else if($name == 'Luzon')
		{
			$shID =  '2';
		}
		else if($name == 'Visayas')
		{
			$shID =  '3';
		}
		else
		{
			$shID =  '4';
		}
		
		$tables = array();
		$tables[0] = 'ex_shipping';
		
		$fields = array();
		$fields[0] = 'perPair';
		
		$whereClause = 'shipID="'.$shID.'"';
		
		$data = SQLRecover($tables, $fields, $whereClause);
		
		$return = array();
		$return['shipID'] = $shID;
		$return['value'] = $data['perPair'][0];
		return $return;
	}
	function chgCart($chg)
	{
		if($chg != 'null')
		{
			$temp = array();
			$temp = $_SESSION['cart'];
			unset($_SESSION['cart']);
			for ($i=0; $i<sizeOf($temp); $i++)
			{
				$values = explode('|', $temp[$i]);
				$_SESSION['cart'][$i] = $values[0].'|'.$values[1].'|'.$_POST['qtyChngd'][$i].'|'.$values[3];
			}
		}
	}
	function delCart($sessionVal)
	{
		if(isset($_SESSION['cart']))
		{
			$temp = array();
			for ($i=0; $i<sizeOf($_SESSION['cart']); $i++)
			{
				if($_SESSION['cart'][$i] != $sessionVal)
				{
					$temp[sizeOf($temp)] = $_SESSION['cart'][$i];
				}
			}
			unset($_SESSION['cart']);
			if(sizeOf($temp) > 0)
			{
				$_SESSION['cart'] = $temp;
			}
			
			unset($temp);
		}
	}
	delCart(get('del'));
	chgCart(get('change'));
	function getItemDetails($itemIndex, $quantity, $tick)
	{	
		$dataSession = explode("|", $itemIndex);
		//0 - itemID, 1 - itemSize, 2 - itemCat (mwa)
		if($dataSession[2] == 'm')
		{
			$cat = 'men';
		}
		else if($dataSession[2] == 'w')
		{
			$cat = 'women';
		}
		else if($dataSession[2] == 'a')
		{
			$cat = 'accessories';
		}
		else
		{
			$cat = '';
		}
		
		$tables = array();
		$tables[0] = 'ex_gallery_'.$dataSession[2];
		
		$fields = array();
		$fields[0] = 'itemID';
		$fields[1] = 'itemName';
		$fields[2] = 'itemPrice';
		$fields[3] = 'itemImg1';
		$fields[4] = 'active';
		$fields[5] = 'itemSubCat';
		$fields[6] = 'deactivate';
		
		$whereClause = 'itemID="'.$dataSession[0].'"';
		
		$data = SQLRecover($tables, $fields, $whereClause);
		$return = array();
			/*
			[0] - id
			[1] - category: m/w/a
			[2] - quantity
			[3] - size
			[4] - session
			*/
			
		//$dataSession[1].' '.$data['itemID'][0].' '.$data['itemName'][0].' '.$data['itemImg1'][0];
		$refValue = $data['itemID'][0].'|'.$dataSession[2].'|'.$quantity.'|'.$dataSession[1].'|'.$tick;
		
		$return['item'] = '<img class="thumbsC imgT" src="./img/categories/'.$cat.'/'.$data['itemSubCat'][0].'/'.$data['itemImg1'][0].'" /><div class="thumbsC divT"><br /><a href="'.INDEX.'product'.EXT.'category='.$cat.'&sub='.$data['itemSubCat'][0].'&id='.$data['itemID'][0].'">'.$data['itemName'][0].'</a><br /><span class="medium">Size: '.$dataSession[1].'</span><br /><input type="button" value="Delete This Entry" class="deletebtns" alt="'.INDEX.'cart'.EXT.'del='.$refValue.'" /></div>';
		
		$discount = ($data['active'][0] == 1 ? 0 : $data['active'][0]/100);
		
		$return['price'] = '<div class="pricesL no"><br />P'.number_format($data['itemPrice'][0] * (1 - $discount), 2, '.', ',').'</div>';
		
		$return['priceDigits'] = $data['itemPrice'][0] * (1 - $discount);
		$return['maxOut'] = $data['deactivate'][0];
		$return['cat'] = ($cat == 'accessories' ? 'a' : 'c');
		
		$return['reFactorVals'] = $refValue;
		
		return $return;
	}
	
	function getShippingDetails()
	{
		$tables = array();
		$tables[0] = 'ex_shipping';
		
		$fields = array();
		$fields[0] = 'shipName';
		$fields[1] = 'perPair';
		$fields[2] = 'shipID';
		
		$whereClause = '`order` > - 1 ORDER BY `order`';
		
		$data = SQLRecover($tables, $fields, $whereClause);
		
		return $data;
	}
	function logShopper($postArray)
	{
		$tables = array();
		$tables[0] = 'ex_shoppers';
		
		$fields = array();
		$fields[0] = 'memberID';
		
		$whereClause = 'email="'.$postArray['email'].'"';
		
		$data = SQLRecover($tables, $fields, $whereClause);
		
		if($data['queryStatus'] == 'DB Query success!')
		{//LOGIN
		
			$tables = array();
			$tables[0] = 'ex_shoppers';
			
			$fields = array();
			$fields[0] = 'memberID';
			
			$whereClause = 'email="'.$postArray['email'].'" AND passphrase = "'.crypt(strip_tags($postArray['pass']), 'ssmain0505032').'"';
			
			$data = SQLRecover($tables, $fields, $whereClause);
			
			if($data['queryStatus'] == 'DB Query success!' && !isset($postArray['cpass']))
			{
				$_SESSION['shopper'] = $data['memberID'][0];
				return 'successful';
			}
			else
			{
				return 'Invalid Email or Passphrase';
				//FORGOT PASSWORD?
			}
		}
		else
		{//MAKE NEW
			/*LOGSHOPPER POST VARS:
				'name' = First Name
				'lName' = Last Name
				'number' = Mobile
				'email' = Email
				'pass' = Password
				'cpass' = Match
				'shipping' = Shipping Address
				'lvm' = Luzon/Visayas/Mindanao
				*/
				
			if($postArray['email']== '' || (!isset($postArray['name']) || $postArray['name'] == '') || (!isset($postArray['number']) || $postArray['number'] == '') || (!isset($postArray['pass']) || $postArray['pass'] == '') || (!isset($postArray['lName']) || $postArray['lName'] == '') || (!isset($postArray['pass']) || !isset($postArray['cpass']) || $postArray['pass'] != $postArray['cpass']) || (!isset($postArray['shipping']) || $postArray['shipping'] == '') || verifyEmail($postArray['email']) == false)
			{
				return 'Please fill up all the fields to continue with your registration. Make sure your email address is valid and both the password and confirm password fields match.';
			}
			
			$tableName = 'ex_shoppers';
			
			$fields = array();
			$fields[0] = 'email';
			$fields[1] = 'name';
			$fields[2] = 'contactNo';
			$fields[3] = 'passphrase';
			$fields[4] = 'expiry';
			$fields[5] = 'mobile';
			$fields[6] = 'address';
			$fields[7] = 'location';
			
			$values = array();
			$values[0] = $postArray['email'];
			$values[1] = $postArray['lName'].', '.$postArray['name'];
			$values[2] = $postArray['number'];
			$values[3] = crypt(strip_tags($postArray['pass']), 'ssmain0505032');
			$values[4] = sqlDate('1 year');
			$values[5] = $postArray['number'];
			$values[6] = $postArray['shipping'];
			$values[7] = $postArray['lvm'];
			
			$data = SQLInsert($tableName, $fields, $values);
			
			
			$tables = array();
			$tables[0] = 'ex_shoppers';
			
			$fields = array();
			$fields[0] = 'memberID';
			
			$whereClause = 'email="'.$postArray['email'].'" AND name LIKE "'.$postArray['lName'].' '.$postArray['name'].'" AND passphrase = "'.crypt(strip_tags($postArray['pass']), 'ssmain0505032').'"';
			
			$data = SQLRecover($tables, $fields, $whereClause);
			
			$_SESSION['shopper'] = $data['memberID'][0];
			return 'successful';
		}
		
	}
	function addCart($toadd)
	{
		if(isset($_SESSION['prevCart']) && $toadd == $_SESSION['prevCart'])
		{
			$toadd = 'null';
		}
		
		if($toadd != 'null')
		{
			$entry = explode("|", $toadd);
			/*
			[0] - id
			[1] - category: m/w/a
			[2] - quantity
			[3] - size
			[4] - session
			*/
			if($entry[2] > 0)
			{
				$tables = array();
				$tables[0] = 'ex_gallery_'.$entry[1];
				
				$fields = array();
				$fields[0] = 'itemID';
				$fields[1] = 'itemName';
				$fields[2] = 'itemPrice';
				$fields[3] = 'active';
				
				$whereClause = 'itemID="'.$entry[0].'"';
				
				$data = SQLRecover($tables, $fields, $whereClause);
				
				if($data['queryStatus'] == 'DB Query success!')
				{
					$track = true;
					$sizeOfSessh = (!isset($_SESSION['cart']) ? 0 : sizeOf($_SESSION['cart']));
					if($sizeOfSessh != 0)
					{
						for ($i=0; $i<$sizeOfSessh; $i++)
						{
							if($_SESSION['cart'][$i] == $toadd)
							{
								$track = false;
							}
						}
					}
					
					if($track)
					{
						$_SESSION['cart'][$sizeOfSessh] = $toadd;
						$_SESSION['prevCart'] = $toadd;
					}
				}
			}
		}
	}
	
	function userExists()
	{
		$shopperLogin = '50650';
		$shopperPass = '26285';
		addCart(get('addCart'));
		if(get('reset') == 'yes')
		{
			unset($_SESSION['cart']);
		}
		
		if(get('myBag') == 'no')
		{
			//DEBUG HERE
			if(isset($_COOKIE[$shopperLogin]))
			{
				$expiresOn = time() - 3600;
				setcookie($shopperLogin, '', $expiresOn);
				setcookie($shopperPass, '', $expiresOn);
			}
			unset($_SESSION['cart']);
			unset($_SESSION['shopper']);
			return redirectSiteNow(INDEX.'cart');
		}
		$return = '
			<div class="container_12">
				<div class="grid_12 crumbs">
					<a href="'.INDEX.'home">Home</a> > <a href="'.INDEX.'cart">My Bag</a>
				</div>
			</div>
			<div class="clear">
			<!--spanner-->
			</div>
			<div class="container_16">
			<div class="grid_1">
				&nbsp;
			</div>
			<div class="grid_14 bagStuff">
				<div class="grid_14 alpha h2Margins">
					<h2>My Bag</h2>
					<div class="bracketLinks"><span class="small">[<a href="'.INDEX.'cart'.EXT.'myBag=no">This is not my bag</a>]<span></div>
				</div>
				<div class="clear">
				<!--spanner-->
				</div>
				<div class="grid_7 alpha headers centerAlign">
				Item
				</div>
				<div class="grid_2 headers centerAlign">
				Price
				</div>
				<div class="grid_1 headers centerAlign">
				Qty
				</div>
				<div class="grid_4 omega headers leftAlign">
				Item Total
				</div>
				<div class="clear">
				<!--spanner-->
				</div>
				<div class="grid_14 alpha spanCap">
					&nbsp;
				</div>
				<div class="clear">
				<!--spanner-->
				</div>
				
		';		
		$gTotal = 0;
		if(!isset($_SESSION['cart']))
		{
			$formHide = '';
			$subHide = '';
			$return .= '
			<div class="clear">
			<!--spanner-->
			</div>
			<div class="grid_14 centerAlign bagProper alpha">
				<br /><br /><br /><br /><br /><br /><br />There are no items in your bag.
			</div>
			<div class="clear">
			<!--spanner-->
			</div>
			';
		}
		else
		{
			//READ: MACHINE LANG > SEARCHABLE LANG
			for ($i=0; $i<sizeOf($_SESSION['cart']); $i++)
			{
				$dataSession = explode('|', $_SESSION['cart'][$i]);
				$itemIDSize[$i] = $dataSession[0].'|'.$dataSession[3].'|'.$dataSession[1];
				$itemQty[$i] = $dataSession[2];
			}
			$shoppingCartItems = array();
			//GET CART VALUES
			for ($i=0; $i<sizeOf($itemIDSize); $i++)
			{
				if(!isset($shoppingCartItems[$itemIDSize[$i]]))
				{
					$shoppingCartItems[$itemIDSize[$i]] = 0;
				}
				$shoppingCartItems[$itemIDSize[$i]] += $itemQty[$i];
			}
						
			$shoppingCartIndices = array();
			$add = true;
			
			for ($i=0; $i<sizeOf($itemIDSize); $i++)
			{
				if(!isset($shoppingCartIndices[0]))
				{
					$shoppingCartIndices[0] = $itemIDSize[$i];
					$add = false;
				}
				else
				{
					$add = true;
					for ($j=0; $j<sizeOf($shoppingCartIndices); $j++)
					{
						if($shoppingCartIndices[$j] == $itemIDSize[$i])
						{
							$add = false;
						}
					}
				}
				
				if($add)
				{
					$shoppingCartIndices[sizeOf($shoppingCartIndices)] = $itemIDSize[$i];
				}
			}
			
			$accessPlus = 0;
			unset($_SESSION['cart']); // UNSET FOR REFACTORING CART
			$itemList = '<table>';
			$formHide = '<form id="hiddenChangeForm" class="linear" action="'.INDEX.'cart'.EXT.'change=yes" method="POST">';
			$subHide = '<form id="mainSubmit" class="linear" action="'.INDEX.'orderSend'.EXT.'address=" method="POST">';
			
			for ($i=0; $i<sizeOf($shoppingCartIndices); $i++)
			{
				$j = $i %2;
				$itemDetails= getItemDetails($shoppingCartIndices[$i], $shoppingCartItems[$shoppingCartIndices[$i]], rand(1,1200));
				
				//REFACTOR CART
				if(!isset($_SESSION['cart']))
				{
					$_SESSION['cart'] = array();
				}
				$_SESSION['cart'][$i] = $itemDetails['reFactorVals'];
				
				
				//---
				$qtyPerItem = ($shoppingCartItems[$shoppingCartIndices[$i]] >= $itemDetails['maxOut'] ? $itemDetails['maxOut'] : $shoppingCartItems[$shoppingCartIndices[$i]]);
				$formHide .= '<input type="hidden" name="qtyChngd['.$i.']" id="qtyHide'.$i.'" value="'.$qtyPerItem.'"/>';
				
				$subHide .= '<input type="hidden" name="z92425['.$i.']" value="'.$itemDetails['reFactorVals'].'"/>';
				/* 
			[0] - id
			[1] - category: m/w/a
			[2] - quantity
			[3] - size
			*/
				$totalG = $itemDetails['priceDigits']*$qtyPerItem;
				
				$accessPlus = ($itemDetails['cat'] == 'a' ? '1' : $accessPlus);
				$qtySelector = '<select class="qtySBox '.$itemDetails['cat'].'" alt="'.$i.'" name="quantity">';
				for ($k=1; $k<=$itemDetails['maxOut']; $k++)
				{
					$selected = ($k == $qtyPerItem ? ' selected' : '');					
					$qtySelector .= '<option value="'.$k.'"'.$selected.'>'.$k.'</option>';
				}
				$qtySelector .= '</select>';
				$itemList .= '				
				<tr class="stripe">
					<td class="tdItem">
						<input type="hidden" id="dataSession['.$i.']" value="'.$shoppingCartIndices[$i].'|'.$shoppingCartItems[$shoppingCartIndices[$i]].'" />
						'.$itemDetails['item'].'
					</td>
					<td class="tdPrice">
						'.$itemDetails['price'].'
					</td>
					<td class="tdQty">
						<div class="qtyL no"><br />'.$qtySelector.'</div>
					</td>
					<td class="tdTotal">
						<div class="ttlL no"><br /><span id="subTDiv'.$i.'">P'.number_format($totalG, 2, '.', ',').'</span></div>
						<input type="hidden" id="dividr'.$i.'" value="'.$qtyPerItem.'" />
						<input type="hidden" id="total'.$i.'" value="'.$totalG.'" />
					</td>
				</tr>
				';
				$gTotal += $totalG;
			}
			
			$itemList .= '</table>';
			$formHide .= '<input type="submit" value="Save Changes"/></form>';
			$return .='
			<div class="clear">
			<!--spanner-->
			</div>
			<div class="grid_14 bagProper alpha">
				'.$itemList.'
			</div>
			<div class="clear">
			<!--spanner-->
			</div>
			<div class="grid_1">
				&nbsp;
			</div>
			<div class="grid_14 resetItems">
			<h3>Purchase Total: PHP <span id="sTotal">'.number_format($gTotal, 2, '.', ',').'</span></h3>&nbsp;&nbsp;&nbsp;&nbsp;<br />
			[<a href="'.INDEX.'cart'.EXT.'reset=yes">Clear All Items</a>]&nbsp;&nbsp;&nbsp;&nbsp;
			</div>	
			<div class="grid_1">
				&nbsp;
			</div>
			<div class="clear">
			<!--spanner-->
			</div>
			
			';
		}
		
		$shipping = getShippingDetails();
		$shipVals = '';
		$lineSkips = '';
		if(isset($shipping['shipName']))
		{
			for ($i=0; $i<sizeOf($shipping['shipName']); $i++)
			{
				$j = sizeOf($shipping['shipName'])-1;
				$shipVals .= '<input type="radio" class="shipRadios" name="shippingOps" value="'.$shipping['perPair'][$i].'" alt="'.$shipping['shipID'][$i].'" />&nbsp;&nbsp;P'.number_format($shipping['perPair'][$i], 2, '.', ',').'/pair '.$shipping['shipName'][$i].($j == $i ? '' : '<br />');
				$lineSkips .= ($j == $i ? '' : '<br />');
			}
		}
		$shippingOwnAdd = decipherShipping(getShopperLocation());
		$subHide .= '<input type="hidden" id="sizeToSend" value="0" name="e46750" />
		<input type="hidden" id="shippingID" value="pickup" name="a38078" />
		<input type="hidden" name="h53209" value="'.$_SESSION['shopper'].'" />
		<input id="placeOrder" type="submit" value="Place Order" /></form>';
		$return .= '
		</div><!--END BAGSTUFF-->
			<div class="grid_1">
				&nbsp;
			</div>
			<div class="clear">
			<!--spanner-->
			</div>
			<div class="grid_1">
				&nbsp;
			</div>
			<div class="grid_14">
			
			</div>
			<div class="grid_14">
				<div class="grid_14 alpha">
					<h3>Shipping Options</h3>
				</div>
				<div class="clear">
				<!--spanner-->
				</div>
				<div class="grid_7 alpha headers2 centerAlign">
				Shipping Options
				</div>
				<div class="grid_3 headers2 centerAlign">
				Qty Items
				</div>
				<div class="grid_3 omega headers2 centerAlign">
				Shipping Fee
				</div>
				<div class="clear">
				<!--spanner-->
				</div>
				<div class="grid_14 alpha spanCap">
					&nbsp;
				</div>
				<div class="clear">
				<!--spanner-->
				</div>
				<div class="grid_7 alpha details2 leftAlign"><br />
					<input type="radio" id="pickup" name="shippingOps" class="shipRadios" value="0" alt="#7 Makaturing St. cor. Banawe, Quezon City" checked/>&nbsp;&nbsp;Pick up at #7 Makaturing St. cor. Banawe, Quezon City<br />
					<input type="radio" id="ownAdd" name="shippingOps" class="shipRadios" value="'.$shippingOwnAdd['value'].'" alt="'.$shippingOwnAdd['shipID'].'"/>&nbsp;&nbsp;P'.$shippingOwnAdd['value'].'.00/pair to '.getShopperAddress().'<br />
					'.$shipVals.'
				</div>
				<div id="addressShopper" style="display:none;" alt="'.getShopperAddress().'"></div>
				<div class="grid_3 details2 centerAlign"><br />
				<br />'.$lineSkips.'Shipped as <span id="totalItemQty"></span> item(s)
				<input type="hidden" id="totalItemQtyF" value="" />
				</div>
				<div class="grid_3 omega details2 centerAlign"><br />
				<br />'.$lineSkips.'<span id="shippingPrice">P0.00</span><br /><br />
				<input type="hidden" id="sTotalForm" value="0" />
				</div>
				<div class="clear">
				<!--spanner-->
				</div>
				<div class="grid_14">
					<div class="resetItems"><br /><span class="small">[<a href="'.INDEX.'shipping" target="_blank">Shipping Details</a>]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><br /><br /></div>
				</div>
				<div class="grid_14 alpha spanCap">
					&nbsp;
				</div>
				<div class="clear">
				<!--spanner-->
				</div>
				<div class="grid_14 alpha totalGrand rightAlign">
				<h4>Grand Total: PHP <span id="gTotalDisplay">'.number_format($gTotal, 2, '.', ',').'</span></h4>
				<input type="hidden" id="grandTotalForm" value="'.$gTotal.'" />
					<div id="finalBtnContainer">
						<div id="sendForm" class="orderSubmit centerAlign">
							'.(!isset($_SESSION['cart']) ? '' : $subHide).'<br /><br />
							<span class="small">[<a href="'.INDEX.'terms" target="_blank">Review Payment Terms</a>]</span>
							<br /><br /><br />
						</div>
						<div id="changeForm" class="orderSubmit centerAlign">
							'.$formHide.'<br /><br />
							<span class="small">[<a href="'.INDEX.'cart">Cancel All Changes</a>]</span>
							<br /><br /><br />
						</div>
					</div>
				</div>
				<div class="grid_1">
					&nbsp;
				</div>
			</div>
			<div class="grid_1">
				&nbsp;
			</div>
			</div>';
		return $return;
	}
	function userNotExists()
	{
		$shopperLogin = '50650';
		$shopperPass = '26285';
		$LVM = '
		<select name="lvm" class="inputbx2">
			<option value="Metro Manila">Metro Manila (MM)</option>
			<option value="Luzon">Luzon (Outside MM)</option>
			<option value="Visayas">Visayas</option>
			<option value="Mindanao">Mindanao</option>
		</select>
		';
		$return = '
			<div class="container_12 logger">
			
		';
		
		if(isset($_COOKIE[$shopperLogin]) && isset($_COOKIE[$shopperPass]))
		{
			//bypass login.
			$postArr['email'] = $_COOKIE[$shopperLogin];
			$postArr['pass'] = $_COOKIE[$shopperPass];
			if(logShopper($postArr) == 'successful')
			{
				/*LOGSHOPPER POST VARS:
				'name' = First Name
				'lName' = Last Name
				'number' = Mobile
				'email' = Email
				'pass' = Password
				'cpass' = Match
				'shipping' = Shipping Address
				'lvm' = Luzon/Visayas/Mindanao
				*/
				addCart(get('addCart'));
				$return = '<div class="grid_12">
					Please wait as we redirect you to your account.
					'.redirectSiteNow(INDEX.'cart').'
				</div>';
			}
		}
		
		if(post('loginMail') != 'null')
		{
			//normal login.
			$shopLog = logShopper($_POST);
			if($shopLog == 'successful')
			{
				/*LOGSHOPPER POST VARS:
				'name' = First Name
				'lName' = Last Name
				'number' = Mobile
				'email' = Email
				'pass' = Password
				'cpass' = Match
				'shipping' = Shipping Address
				'lvm' = Luzon/Visayas/Mindanao
				*/
				if(post('cookiez') == 'keepLoggedIn')
				{	
					$expiresOn = 2592000+time();
					setcookie($shopperLogin, post('email'), $expiresOn);
					setcookie($shopperPass, post('pass'), $expiresOn);
				}
				
				addCart(get('addCart'));
				$return = '<div class="grid_12">
					Please wait as we redirect you to your account.
					'.redirectSiteNow(INDEX.'cart').'
				</div>';
			}
			else
			{
				//POST UPON SIGN IN ERROR
				//ACTION URL: "'.INDEX.'cart'.(get('addCart') != 'null' ? EXT.'addCart='.get('addCart') : '').'"
				//HIDDEN VAR: <input type="hidden" value="notNull" name="loginMail"/>
				/*CSS TABLES:
				class - tHeader: Headers <th>
				class - tdL: Labels
				class - tdR: forms
				class - tdB: all that have colspan 2
				*/
				$ss['Manila'] = '';
				$ss['Luzon'] = '';
				$ss['Visayas'] = '';
				$ss['Mindanao'] = '';
				
				if(isset($ss[post('lvm')]))
				{
					$ss[post('lvm')] = ' selected';
				}
				$checkers = (post('s') == 'mailingList' ? ' checked' : '');
				$LVM = '
				<select name="lvm" class="inputbx2">
					<option value="Manila"'.$ss['Manila'].'>Metro Manila (MM)</option>
					<option value="Luzon"'.$ss['Luzon'].'>Luzon (Outside MM)</option>
					<option value="Visayas"'.$ss['Visayas'].'>Visayas</option>
					<option value="Mindanao"'.$ss['Mindanao'].'>Mindanao</option>
				</select>
				';
				//UPON LOGIN/SIGNUP ERROR
				if(get('sign') == 'up')
				{
					if($shopLog == 'Invalid Email or Passphrase')
					{
						$valueMsg = '<div style="font-size: 8pt; color: #777; margin-top: 5px; font-weight: bold;">There is already an existing account that uses the email address you entered. Please enter a different email address and try again.</div>';
					}
					else
					{
						$valueMsg = '<div style="font-size: 8pt; color: #777; margin-top: 5px; font-weight: bold;">'.$shopLog.'</div>';
					}
					$return .= '
					<div class="grid_12">
						<h2>Set Up Your Account</h2>
					</div>
					<div class="clear">
					<!--spanner-->
					</div>
					<div class="grid_12">
					<h5>Please enter your details below. All your details are required to complete the set up of your account. <a href="#"><u>Privacy Policy</u></a></h5>
					'.$valueMsg.'
					<form method="POST" action="'.INDEX.'cart'.EXT.'sign=up'.(get('addCart') != 'null' ? EXT.'&addCart='.get('addCart') : '').'">
					<table class="signUpForm">
						<tr>
							<td colspan="2" class="tHeader">
								Name and Contact Information<input type="hidden" value="notNull" name="loginMail"/>
							</td>
						</tr>
						<tr>
							<td class="tdLUp">
								First Name:
							</td>
							<td class="tdRUP">
								<input type="text" name="name" class="inputbx" value="'.post('name').'"/>
							</td>
						</tr>
						<tr>
							<td class="tdLUp">
								Last Name:
							</td>
							<td class="tdRUP">
								<input type="text" name="lName" class="inputbx" value="'.post('lName').'"/>
							</td>
						</tr>
						<tr>
							<td class="tdLUp">
								Mobile:
							</td>
							<td class="tdRUP">
								<input type="text" name="number" class="inputbx"  value="'.post('number').'"/>
							</td>
						</tr>
						<tr>
							<td class="tdLUp">
								Shipping Address:
							</td>
							<td class="tdRUP">
								<input type="text" name="shipping" class="inputbx"  value="'.post('shipping').'"/>
							</td>
						</tr>
						<tr>
							<td class="tdLUp">
								Address Location:
							</td>
							<td class="tdRUP">
								'.$LVM.'
							</td>
						</tr>
						<tr>
							<td colspan="2" class="tHeader">
								Email and Password
							</td>
						</tr>
						<tr>
							<td class="tdLUp">
								Email:
							</td>
							<td class="tdRUP">
								<input type="text" name="email" class="inputbx"  value="'.post('email').'"/>
							</td>
						</tr>
						<tr>
							<td class="tdLUp">
								Password:
							</td>
							<td class="tdRUP">
								<input type="password" name="pass" class="inputbx"  value="'.post('pass').'"/>
							</td>
						</tr>
						<tr>
							<td class="tdLUp">
								Confirm Password:
							</td>
							<td class="tdRUP">
								<input type="password" name="cpass" class="inputbx" /><br />
								<input class="ckbox" type="checkbox" value="mailingList" name="s"'.$checkers.'/> Sign me up for Sole Service newsletters and promos through email
							</td>
						</tr>
						<tr>
							<td colspan="2">
								<input type="submit" value="Create Account" class="loginB" />
							</td>
						</tr>
					</table>
					</form>
					</div>
					';
				}
				else
				{
					$return .= '
					<div class="grid_12">
						<h2>Sign In To Your Account</h2>
					</div>
					<div class="clear">
					<!--spanner-->
					</div>
					<div class="grid_6">
						<form method="POST" action="'.INDEX.'cart'.(get('addCart') != 'null' ? EXT.'addCart='.get('addCart') : '').'">
						<h3>Log-in Returning Customers:</h3>
						<h4>Invalid email address and/or password.</h4>
						'.(get('renew') == 'yes' ? 'Your password has been renewed. You can now log into your account.' : '').'
						<table class="signInForm">
							<tr>
								<td class="tdL">
									Email:<input type="hidden" value="notNull" name="loginMail"/>
								</td>
								<td class="tdR">
									<input type="text" name="email" class="inputbx" value="'.post('email').'"/>
								</td>
							</tr>
							<tr>
								<td class="tdL">
									Password:
								</td>
								<td class="tdR">
									<input type="password" name="pass" class="inputbx" value="'.post('pass').'"/>
									<input class="ckbox" type="checkbox" value="keepLoggedIn" name="cookiez" /> Always remember user
								</td>
							</tr>
							<tr>
								<td colspan="2">
									<input type="submit" value="Log In" class="loginB" /></form>
								</td>
							</tr>
						</table>
						<a href="'.INDEX.'fp'.EXT.'tick='.rand(10000,99999).'0'.rand(10000,99999).'1'.rand(10000,99999).'" id="fyp">Forgot your password?</a>
					</div>
					<div class="grid_6">
						<h3>New Customers:</h3>
						<h4>First time buying from us? Make shipping easier by creating your own account.</h4>
						<ul class="newCust">
							<li>Check out faster</li>
							<li>Have a default shipping address</li>
							<li>Track your order</li>
							<li>Review Order Information</li>
						</ul>
						<input type="button" class="linkButton loginC" alt="'.INDEX.'cart'.EXT.'sign=up'.(get('addCart') != 'null' ? EXT.'&addCart='.get('addCart') : '').'" value="Create An Account" />
					</div>
					';
				}
			}
			
		}
		else
		{
			//POST UPON CREATE/SIGN IN ACCOUNT PAGE DIRECT LINK
				//ACTION URL: "'.INDEX.'cart'.(get('addCart') != 'null' ? EXT.'addCart='.get('addCart') : '').'"
				//HIDDEN VAR: <input type="hidden" value="notNull" name="loginMail"/>
				/*CSS TABLES:
				class - tHeader: Headers <th>
				class - tdL: Labels
				class - tdR: forms
				class - tdB: all that have colspan 2
				*/
			
			if(get('sign') == 'up')
			{//CREATE NEW -- NO SUBMISSIONS
				$return .= '
				<div class="grid_12">
					<h2>Set Up Your Account</h2>
				</div>
				<div class="clear">
				<!--spanner-->
				</div>
				<div class="grid_12">
				<h5>Please enter your details below. All your details are required to complete the set up of your account. <a href="#"><u>Privacy Policy</u></a></h5>
				<form method="POST" action="'.INDEX.'cart'.EXT.'sign=up'.(get('addCart') != 'null' ? EXT.'&addCart='.get('addCart') : '').'">
				<table class="signUpForm">
					<tr>
						<td colspan="2" class="tHeader">
							Name and Contact Information<input type="hidden" value="notNull" name="loginMail"/>
						</td>
					</tr>
					<tr>
						<td class="tdLUp">
							First Name:
						</td>
						<td class="tdRUP">
							<input type="text" name="name" class="inputbx"/>
						</td>
					</tr>
					<tr>
						<td class="tdLUp">
							Last Name:
						</td>
						<td class="tdRUP">
							<input type="text" name="lName" class="inputbx"/>
						</td>
					</tr>
					<tr>
						<td class="tdLUp">
							Mobile:
						</td>
						<td class="tdRUP">
							<input type="text" name="number" class="inputbx"/>
						</td>
					</tr>
					<tr>
						<td class="tdLUp">
							Shipping Address:
						</td>
						<td class="tdRUP">
							<input type="text" name="shipping" class="inputbx"/>
						</td>
					</tr>
					<tr>
						<td class="tdLUp">
							Address Location:
						</td>
						<td class="tdRUP">
							'.$LVM.'
						</td>
					</tr>
					<tr>
						<td colspan="2" class="tHeader">
							Email and Password
						</td>
					</tr>
					<tr>
						<td class="tdLUp">
							Email:
						</td>
						<td class="tdRUP">
							<input type="text" name="email" class="inputbx" />
						</td>
					</tr>
					<tr>
						<td class="tdLUp">
							Password:
						</td>
						<td class="tdRUP">
							<input type="password" name="pass" class="inputbx" />
						</td>
					</tr>
					<tr>
						<td class="tdLUp">
							Confirm Password:
						</td>
						<td class="tdRUP">
							<input type="password" name="cpass" class="inputbx" /><br />
							<input class="ckbox" type="checkbox" value="mailingList" name="s" checked/> Sign me up for Sole Service newsletters and promos through email
						</td>
					</tr>
					<tr>
						<td colspan="2">
							<input type="submit" value="Create Account" class="loginB" />
						</td>
					</tr>
				</table>
				</form>
				</div>
				';
			}
			else
			{//LOGIN -- NO SUBMISSIONS / DIRECT LINK
				$return .= '
				<div class="grid_12">
					<h2>Sign In To Your Account</h2>
				</div>
				<div class="clear">
				<!--spanner-->
				</div>
				<div class="grid_6">
					<form method="POST" action="'.INDEX.'cart'.(get('addCart') != 'null' ? EXT.'addCart='.get('addCart') : '').'">
					<h3>Log-in Returning Customers:</h3>
					<h4>Enter your email and password to sign in and manage your account.</h4>
					'.(get('renew') == 'yes' ? 'Your password has been renewed. You can now log into your account.' : '').'
					<table class="signInForm">
						<tr>
							<td class="tdL">
								Email:<input type="hidden" value="notNull" name="loginMail"/>
							</td>
							<td class="tdR">
								<input type="text" name="email" class="inputbx"/>
							</td>
						</tr>
						<tr>
							<td class="tdL">
								Password:
							</td>
							<td class="tdR">
								<input type="password" name="pass" class="inputbx"/>
								<input class="ckbox" type="checkbox" value="keepLoggedIn" name="cookiez" /> Always remember user
							</td>
						</tr>
						<tr>
							<td colspan="2">
								<input type="submit" value="Log In" class="loginB" /></form>
							</td>
						</tr>
					</table>
					<a href="'.INDEX.'fp'.EXT.'tick='.rand(10000,99999).'0'.rand(10000,99999).'1'.rand(10000,99999).'" id="fyp">Forgot your password?</a>
				</div>
				<div class="grid_6">
					<h3>New Customers:</h3>
					<h4>First time buying from us? Make shipping easier by creating your own account.</h4>
					<ul class="newCust">
						<li>Check out faster</li>
						<li>Have a default shipping address</li>
						<li>Track your order</li>
						<li>Review Order Information</li>
					</ul>
					<input type="button" class="linkButton loginC" alt="'.INDEX.'cart'.EXT.'sign=up'.(get('addCart') != 'null' ? EXT.'&addCart='.get('addCart') : '').'" value="Create An Account" />
				</div>
				';
			}
			
			
		}
		$return .= '</div>';
		return $return;
	}
	function displayPage()
	{		
		$output = '<div id="markCart"></div>'.(session('shopper') == 'null' ? userNotExists() : userExists());
		return $output;
	}
?>